package exams.test;

public class Solution {

    public int i;

    public Solution() {
        maxSubString("");
    }

    public static void  main(String[] args){
        Solution solution = new Solution();
        System.out.println(solution.i);

        System.out.println(maxSubString("abcd12345ed125ss123058789"));
    }


    // 给定一个字符串，输出字符串中连续最长的数字串。如果存在长度一样的连续数字串，返回最大的连续数字串。样例：abcd12345ed125ss123058789， 输出123058789。
    //
    //字符串长度在[0, 50000]范围内。
    public static String maxSubString(String s) {
        String res = "";
        String[] arr = s.split("");
        int p = 0;
        int maxL = 0;
        String temp = "";

        for(int i =0; i<= s.length(); i++) {
            if(i == s.length()) {
                if(i - p > maxL) {
                    res = temp;
                    maxL = i -p;
                    break;
                }
            }
            if(isNumber(arr[i])) {
                temp += arr[i];
            } else {
                if(i - p > maxL) {
                    res = temp;
                    maxL = i -p;
                }
                p = i;
                temp = "";
                if(i == s.length() - 1 && !isNumber(arr[i])) {
                    break;
                }
            }
        }
        return res;
    }

    public static boolean isNumber(String s) {
        try {
            Integer.parseInt(s);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
